import { Button, Toast } from "antd-mobile";
import { connect } from "react-redux";
import React, { Component } from "react";
import { $pre } from '../../http/http';
import Header from "../../components/Header/Header";
import { bindActionCreators } from "redux";
import "./Detail.less"
import { actions,getGoodsinfo,getInfo } from "../../store/modules/detail";

class Detail extends Component {
  componentDidMount() {
    let id = this.props.match.params.id;
    let {detail:{getList}} = this.props
    getList(id)
  }
  render() {
    let { info,detail:{toCar}}= this.props
    let goodsid = this.props.match.params.id
    return (
      <div>
        <Header title="商品详情" back></Header>
        <div className="detail-shop">
          <img src={$pre+info.img} alt="" />
          <h3>名称：{info.goodsname}</h3>
          <h3>价格：{info.price}</h3>
          <div>市场价格：{info.market_price}</div>
          <div>描述：{info.description}</div>
          <Button color="primary" onClick={() => toCar(goodsid)}>加入购物车</Button>
        </div>
      </div>
    );
  }
}
const mapStateToProps = (state) => {
  return {
    info:getInfo(state)
  };
};
const mapDispatchToProps = (dispatch) => {
  return {
    detail: bindActionCreators(actions, dispatch),
  };
};
export default connect(mapStateToProps, mapDispatchToProps)(Detail);
